addpath('/Users/marcelomattar/Dropbox/Marcelo/UPenn/Documents/Projects/AdaptID/Scripts/Analyses/ROI_Analysis/1-back_adaptation_drawnFFAs');

subjectList = {...
    'N072912R'...
    'A080512A'...
    'R091412V'...
    'K091412S'...
    'M101012R'...
    };

ADAPT_t_thresh = 1.65;
%ADAPT_t_thresh = -Inf;
subjectsDir = '/Users/marcelomattar/Data/AdaptID/Subjects/';
FFAcontrast = 2; %1 for Faces-Objects, 2 for Faces-Scenes

numSubjects = length(subjectList);
distributionOfBetas = cell(1,numSubjects);

for subjIndx = 1:numSubjects
    
    % For subject A080512A, use the FFA mask based on the main effect
    % contrast
    if strcmp(subjectList{subjIndx},'A080512A')
        [averageBetas maskedBetas] = extractROImask(subjectList{subjIndx}, ADAPT_t_thresh, 3, subjectsDir);
    else
        [averageBetas maskedBetas] = extractROImask(subjectList{subjIndx}, ADAPT_t_thresh, FFAcontrast, subjectsDir);
    end
    
    if size(maskedBetas,1) == 3
        distributionOfBetas{1,subjIndx} = [maskedBetas{1,1}; maskedBetas{2,1}; maskedBetas{3,1}];
    else
        distributionOfBetas{1,subjIndx} = [maskedBetas{1,1}; maskedBetas{2,1}; maskedBetas{3,1}; maskedBetas{4,1}];
    end
end


plotheight = 500;
xlimits = 150;

for subjIndx = 1:numSubjects
    subplot(1,numSubjects,subjIndx);
    %hist(distributionOfBetas{1,subjIndx},-140:10:150);
    h = histfit(distributionOfBetas{1,subjIndx});
    axis([-xlimits xlimits 0 plotheight])
    title(subjectList{subjIndx});
    
    set(h(1),'facecolor',[0.5 0.5 0.5]);
    set(h(2),'linewidth',2);
    [muhat,sigmahat] = normfit(distributionOfBetas{1,subjIndx});
    hold on;
    plot([muhat-2*sigmahat muhat-2*sigmahat],[0 plotheight],'b','linewidth',1);
    plot([muhat+2*sigmahat muhat+2*sigmahat],[0 plotheight],'b','linewidth',1);
    plot([muhat muhat],[0 plotheight],'b','linewidth',2);
end